#include <stdio.h>
int test(char operate[][21],int c,int* pace,int N,int M)
{
	int row=0;
	int col=c-1;
	char visited[20][21]={0};
	while(*pace<2000)
	{
		if(visited[row][col])
		{
			return 0;
		}
		visited[row][col]=1;
	    if(operate[row][col]=='E')
	   {
	   	if(col==M-1)
	   	{
	   		return 1;
		   }
	   	col++;
	   	
	   }
	   else if(operate[row][col]=='W')
	   {
	   	if(col==0)
	   	{
	   		return 1;
		   }
	   	col--;
	   	
	   }
	   else if(operate[row][col]=='N')
	   {
	   	if(row==0)
	   	{
	   	return 1;
		   }
	   	row--;
	   	
	   }
	   else if(operate[row][col]=='S')
	   {
	   	if(row==N-1)
	   	{
	   		return 1;
		   }
	   	row++;
	   	
	   }
	   	(*pace)++;
	}
}
int main()
{
	int N,M,c,pace=1;
	scanf("%d %d %d",&N,&M,&c);
	char operate[20][21];
	for(int i=0;i<N;i++)
	{
		scanf("%s",operate[i]);
	}
	int judge=test(operate,c,&pace,N,M);
	if(judge==1)
	{
		printf("%s %d","out",pace);
	}
	else
	{
		printf("%s %d","loop",pace-1);
	}
    	return 0;
}
